home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
tn3270
/
saio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-17
|
12KB
|
483 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.4d7 April, 1992
* Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#if !defined(USEDUMP)
#include "maclib.h"
#include "termdef.h"
#include "tn3270funcs.h"
#include "globals.h"
#else
#pragma load "tn3270DumpFile"
#endif
#pragma segment 3270sa
extern main(); /* for debugging */
unsigned char *sarcvbuff;
OSErr sa_init(void)
{
Handle version;
short i;
putln("sa_init called");
/* version info. for debugging */
strcpy(dbgmsg, "Version string: ");
version = GetResource('GFTM', 0);
if (version != 0) {
i = strlen(dbgmsg);
memcpy(dbgmsg+i, (*version)+1, (*version)[0]);
dbgmsg[i+(*version)[0]] = 0;
}
else strcpy(dbgmsg, "Version string not available.");
putln(dbgmsg);
strcpy(dbgmsg, "VM file transfer version: ");
version = GetResource('WSFR', 161);
if (version != 0) {
i = strlen(dbgmsg);
memcpy(dbgmsg+i, (*version)+13, (*version)[12]-1);
dbgmsg[i+(*version)[12]-1] = 0;
while (dbgmsg[i] != 0) {
dbgmsg[i] = ((unsigned char *)(*xtabh))[dbgmsg[i]];
i++;
}
}
else strcpy(dbgmsg, "VM file transfer version unknown.");
putln(dbgmsg);
sprintf(dbgmsg, "main at %lx", main); /* in case we're using a map */
putln(dbgmsg); /* for debugging */
/* allocate receive buffers */
sarcvbuff = (unsigned char *)NewPtr(614L); /* 550 + 64 */
if (sarcvbuff == 0L) {
stgalert("sa rcv buffer", "NewPtr", 614L);
return(-1);
}
return(0);
}
void sadflthost(unsigned char *s)
{
strcpy(s, "?"); /* If "?", prompt will be issued */
}
long sagetrsrv(cnr *cp)
{
#pragma unused(cp)
return(0);
}
void salgin(cnr *cp)
{
OSErr rc;
login_init(cp);
cp->connstate = 4;
cp->online = 1;
cp->kblcode = 2;
if (cp->myWindow == 0) {
rc = createwindow(cp);
if (rc != noErr) {
salgout(0, cp);
}
}
else {
newstat(cp);
}
/* if the session was opened by the api, we
delay registering the session until data
is received. (See telnet.c) */
if (!(cp->apiopenpend)) {
apiregister(1, cp);
}
if (cp->serverconn) {
cp->servermode = 0;
srvswitch(cp);
if (!(cp->logon)) {
if (cp->kblock) {
cp->kblock = 0;
newstat(cp);
}
cp->hadascii = 1;
return;
}
}
sendinit(0xc7, cp);
}
void sendinit(unsigned char wcc, cnr *cp)
{
static unsigned char initdata[] =
{0x01, 0xc7, 0x11, 0x5d, 0x6b, 0x1d, 0x60, 0xd9, 0xe4,
0xd5, 0xd5, 0xc9, 0xd5, 0xc7, 0x40, 0x40, 0x40, 0xc2,
0xd9, 0xd6, 0xe6, 0xd5, 0xe5, 0xd4, 0x40, 0x40, 0x1d,
0x40};
initdata[1] = wcc;
memcpy(sarcvbuff+64, initdata, sizeof(initdata));
if (cp->cs.dblevel > 2)
dbgdump("sendinit", sarcvbuff+64, sizeof(initdata));
sadata(sarcvbuff+64, sizeof(initdata), 1, 1, cp);
if (cp->wr_active && (!(cp->needwrite))) {
cp->wr_active = 0;
newstat(cp);
}
if (cp->fsinv && (cp->data_init == 1)) { /* 3270 mode */
cp->fsinv = 0;
invldscr(cp);
if (cp->pndbeep) {
cp->pndbeep = 0;
beep(cp);
}
}
else if (cp->logon == 0) { /* line mode */
if (cp->pndbeep) {
cp->pndbeep = 0;
beep(cp);
}
}
}
void salgout(char keep, cnr *cp)
{
sessionlgout(keep, cp);
}
void sa_end(void)
{
putln("sa_end called");
if (sarcvbuff != 0) {
DisposPtr(sarcvbuff);
sarcvbuff = 0;
}
}
void sawrite(unsigned char *dptr, short dsize, cnr *cp)
{
cp->online = 0;
newstat(cp);
if (cp->cs.dblevel > 2) dbgdump("sawrite", dptr, dsize);
cp->online = 1;
newstat(cp);
sendinit(0xc3, cp);
}
void sain(unsigned char asc, unsigned char chr, unsigned char shift, cnr *cp)
{
if (!(cp->logon)) { /* Return or CLEAR for new session, else beep */
if (cp->connstate == 0) kbnew(chr, cp);
else if ((cp->connstate == 4) && (!(cp->kblock)))
sakbin(asc, chr, shift, cp);
else beep(cp);
return;
}
if (chr == 196) { /* perform program reset immediately */
sa_reset(cp);
xfrst(cp);
invldscr(cp);
return;
}
if (chr == 185) { /* perform keyboard immediately */
hndkbd(chr, shift, cp);
return;
}
if (chr == 197) { /* perform print screen immediately */
prscreen(cp);
return;
}
if ((cp->kbqsize == KBQMAX) || (cp->vmxbgn && (!(cp->vmxsub)))) {
beep(cp); /* error if xfer mode or queue full */
kerr(3, cp);
}
else { /* else add to keyboard queue */
cp->kbqueue[cp->kbqsize].code = chr;
cp->kbqueue[cp->kbqsize].shift = shift;
cp->kbqsize++;
}
}
void sa_reset(cnr *cp)
{
if (cp->logon) {
cp->kblock = cp->kblcode = 0;
cp->online = 1;
}
cp->lastwcc = 0x02;
cp->kb_err = 0;
cp->kbqsize = 0;
cp->aplmode = cp->insmode = 0;
cp->fixbracket = cp->cs.std_brack && (!(cp->aplmode)) &&
(cp->stdfont != ALAFONT);
newstat(cp);
}
void saevent(void)
{
static unsigned long * Ticks = (unsigned long *)0x16a;
short i, j;
cnr *cp;
short kindex;
unsigned long klimit;
CursHandle watchHandle;
char waitcur;
for (j=0; j < MAXSESSIONS; j++) {
cp = cplist[j];
if (cp != 0) {
if ((cp->serflg == 0) && (cp->tcpflg == 0)) {
kindex = 0;
klimit = (*Ticks) + 15;
waitcur = 0;
if (cp->pasteactive == 0) {
while ((cp->kbqsize > 0) && (!(cp->kblock))) {
if (cp->vmxbgn && (!(cp->vmxsub))) break;
if (cp->pasteactive) break;
if (((cp->kbqueue)[kindex].shift) == 100) {
cp->pasteactive = 1;
}
else {
hndkbd((cp->kbqueue)[kindex].code,
(cp->kbqueue)[kindex].shift, cp);
}
kindex++;
cp->kbqsize--;
if ((*Ticks) > klimit) {
klimit = (*Ticks) + 15;
if (waitcur == 0) {
watchHandle = GetCursor(4);
SetCursor(*watchHandle);
waitcur = 1;
dfltcurs = 2;
}
}
}
if ((cp->kbqsize > 0) && (kindex > 0)) {
for (i = 0; i < cp->kbqsize; i++) {
(cp->kbqueue)[i].code = (cp->kbqueue)[i+kindex].code;
(cp->kbqueue)[i].shift = (cp->kbqueue)[i+kindex].shift;
}
}
}
else { /* pasteactive true */
while ((cp->pastebuffsize > 0) && (!(cp->kblock))) {
if (cp->vmxbgn && (!(cp->vmxsub))) break;
hndkbd((cp->pastebuff)[kindex], 99, cp);
kindex++;
cp->pastebuffsize--;
if ((*Ticks) > klimit) {
klimit = (*Ticks) + 15;
if (waitcur == 0) {
watchHandle = GetCursor(4);
SetCursor(*watchHandle);
waitcur = 1;
dfltcurs = 2;
}
}
}
if ((cp->pastebuffsize > 0) && (kindex > 0)) {
for (i = 0; i < cp->pastebuffsize; i++) {
(cp->pastebuff)[i] = (cp->pastebuff)[i+kindex];
}
}
if (cp->pastebuffsize == 0) {
cp->pasteactive = 0;
DisposPtr(cp->pastebuff);
cp->pastebuff = 0;
if (cp->pastebeep) beep(cp);
newwrite(cp);
newcur(cp);
}
}
}
}
}
}
void sadata(unsigned char *sptr, short slen,
char init, char end, cnr *cp)
{
short wsflen;
unsigned char * dataptr;
short datalen;
char winit;
if (cp->cs.dblevel > 2) {
sprintf(dbgmsg, "sadata: len = %d, init = %d, end = %d",
slen, init, end);
putln(dbgmsg);
}
if (cp->apiopenpend) {
apiregister(1, cp); /* register session */
if (!(cp->logon)) {
apiopenresp(openLineMode, cp);
}
else {
apiopenresp(open3270Mode, cp);
}
}
if (!(cp->logon)) {
cp->kblock = cp->kblcode = 0;
cp->showfkey = 1; /* enable fkey menu */
appl_menu();
cp->connstate = 5;
cp->logon = 1;
newstat(cp);
}
/* length 0 valid only if init==0 and end==1 */
if ((slen == 0) && (init || (!end))) return;
if (init) {
cp->wsfflag = ((sptr[0] == 0x11) || (sptr[0] == 0xf3));
if (cp->wsfflag) {
cp->wsfptr = cp->wsfbuff;
cp->wsfleft = 8192;
cp->wsfop = sptr[0];
}
}
if (cp->wsfflag) {
if (slen > 0) {
if (slen > cp->wsfleft) wsflen = cp->wsfleft;
else wsflen = slen;
memcpy(cp->wsfptr, sptr, wsflen);
cp->wsfleft -= wsflen;
cp->wsfptr += wsflen;
}
if (end) {
if (cp->cs.dblevel > 1) dbgdump("writesf", cp->wsfbuff,
cp->wsfptr-cp->wsfbuff);
writesf(cp->wsfbuff, cp->wsfptr-cp->wsfbuff, 1, cp);
writeresponse(cp->wsfop, cp);
}
return;
}
if (init) {
cp->lstopcd = sptr[0];
cp->xtralen = cp->xtrainit = 0;
cp->needtoend = 0;
}
switch (cp->lstopcd) {
case 0x01: /* write */
case 0x05: /* erase/write */
case 0x0d: /* erase/write alt. */
case 0xf1: /* SNA write */
case 0xf5: /* SNA erase/write */
case 0x7e: /* SNA erase/write alt. */
if (init && (slen == 1)) { /* just op-code */
cp->xtralen = 1; /* save op-code until wcc */
cp->xtradata[0] = sptr[0];
cp->xtrainit = 1;
break;
}
if (slen > 0) {
cp->needtoend = 1;
if (cp->xtralen > 0)
memcpy(sptr-cp->xtralen, cp->xtradata, cp->xtralen);
cp->ldvoff = 0;
dataptr = sptr-cp->xtralen;
datalen = slen + cp->xtralen;
if (cp->xtrainit) winit = 1;
else winit = init;
if (cp->cs.dblevel > 1) {
sprintf(dbgmsg, "writetm: init = %d", winit);
dbgdump(dbgmsg, dataptr, datalen);
}
writetm(dataptr, datalen, winit, cp);
cp->xtralen = datalen - cp->ldvoff;
cp->xtrainit = 0;
if (cp->xtralen == 0) break;
if (cp->xtralen > 64) cp->xtralen = 64;
memcpy(cp->xtradata, dataptr+cp->ldvoff, cp->xtralen);
}
break;
case 0x0f: /* erase all unprot. */
case 0x6f: /* SNA erase all unprot. */
if (!init) return;
funckey(10, 0, cp);
cp->rdaid = 60;
writeresponse(cp->lstopcd, cp);
return;
case 0x06: /* read modified */
case 0xf6: /* SNA read modified */
if (!init) return;
rdmcmd(cp->rdaid, cp);
writeresponse(cp->lstopcd, cp);
return;
case 0x6e: /* SNA read modified all */
if (!init) return;
rdmacmd(cp->rdaid, cp);
writeresponse(cp->lstopcd, cp);
return;
case 0x02: /* read buffer */
case 0xf2: /* SNA read buffer */
if (!init) return;
rdbuff(cp);
writeresponse(cp->lstopcd, cp);
return;
default:
return;
}
if (end) {
if (cp->needtoend) {
endwcc(cp); /* sets pndbeep if beep needed */
writeresponse(cp->lstopcd, cp);
cp->needtoend = 0;
}
cp->fsinv = 1; /* saevent will call invldscr and possibly beep */
}
}
void sakbin(unsigned char asc, unsigned char chr,
unsigned char shift, cnr *cp)
{ /* handle new character in line mode */
#pragma unused(chr, shift)
unsigned char c;
if (asc > 127) return;
c = asc;
sawrite(&c, 1, cp);
}